<template>
  <div class="app-container">
    <el-table v-loading="loading" :data="list">
      <el-table-column label="编号" align="center" sortable prop="id" width="120" />
      <el-table-column label="功能" align="center" prop="name" />
      <el-table-column label="显示隐藏" align="center" prop="show">
        <template slot-scope="scope">
          <el-switch v-model="scope.row.show" active-color="#00E266" @change="handleSwitchChange(scope.row)"></el-switch>
        </template>
      </el-table-column>
    </el-table>

    <pagination
        v-show="total>0"
        :total="total"
        :page.sync="queryParams.pageNum"
        :limit.sync="queryParams.pageSize"
        @pagination="getList"
    />
  </div>
</template>

<script>
import { getFunctionList, showFunction } from "@/api/shuiyin/shuiyin";

export default {
  name: "Function",
  data() {
    return {
      // 遮罩层
      loading: true,
      // 总条数
      total: 0,
      // 功能管理表格数据
      list: [],
      // 查询参数
      queryParams: {
        pageNum: 1,
        pageSize: 10
      },
    };
  },
  created() {
    this.getList();
  },
  methods: {
    /** 查询功能管理列表 */
    getList() {
      this.loading = true;
      getFunctionList(this.queryParams).then(response => {
        this.list = response.data.rows;
        this.total = response.data.total;
        this.loading = false;
      });
    },

    handleSwitchChange(row) {
      const functionId = row.id;
      showFunction(functionId).then(response => {
        if (response.status === 200) {
          this.$message.success('修改成功');
          this.getList();
        }
      })
    }
  }
};
</script>
